package com.lhkj.ct.admin.modules.warning.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.warning.model.entity.TblScaleWarnRecord;
import com.lhkj.ct.meta.modules.warning.service.ScaleWarnRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 *      预警记录 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-10-17
 */
@RestController
@RequestMapping("api/plat/warning/record")
@Api(tags = {"3.1预警记录"})
@Validated
public class WarnRecordController {

    @Resource
    private ScaleWarnRecordService warnRecordService;

    @GetMapping(value = "list")
    @ApiOperation(value = "列表查询接口")
    public ActionResult<IPage<TblScaleWarnRecord>> list(TblScaleWarnRecord record, PageQuery pageQuery) {
        return ActionResult.success( warnRecordService.selectWarnPage(record, pageQuery));
    }

    @PostMapping(value = "handle")
    @ApiOperation(value = "处理")
    @Log(title = "预警记录", actionType = ActionType.UPDATE)
    public ActionResult<Void> handle(@NotEmpty(message = "请选择预警记录") @RequestBody List<String> ids) {
        return ActionResult.judge( warnRecordService.handle(ids));
    }

    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除")
    @Log(title = "预警记录", actionType = ActionType.DELETE)
    public ActionResult<IPage<TblScaleWarnRecord>> list(@NotEmpty(message = "请选择预警记录") @RequestBody List<String> ids) {
        int count = warnRecordService.removeByIds(ids);
        return ActionResult.success(String.format("操作成功，共删除[%d]条", count));
    }
}
